home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Sample Applications / Power Examples / SortPicts / Source / main.cp < prev    next >
Encoding:
Text File  |  1994-06-03  |  4.4 KB  |  153 lines  |  [TEXT/MPS ]

  1. /*************************************************************************************
  2.  *
  3.  *    Object Oriented Shell
  4.  *
  5.  *    Main.cp - C Source File
  6.  *
  7.  *      Copyright © Apple Computer, Inc. 1988 - 1993
  8.  *      All rights reserved.
  9.  *
  10.  *    This file contains the initialization code for SortPicts.
  11.  *    It will call GWorldObj for the first time.
  12.  *    GWorldObj.InitObj will initialize any static (i.e. global variables) it uses.
  13.  *
  14.  *************************************************************************************/
  15.  
  16. #include "WindowObj.Link"
  17. #include "main.h"
  18. #include "Traps.h"
  19.  
  20.  
  21. /**************************************************************************************
  22.  
  23.     The "g" prefix is used to emphasize that a variable is global.
  24.     
  25. ***************************************************************************************/
  26.  
  27. SysEnvRec    gMac;
  28. Boolean        gQuit;
  29. Boolean        gInBackground;
  30.  
  31. //        the QDGlobals are very special.
  32. //        68K gives them to developers as the data structure just before
  33. //            the Jump Table (theres a pointer at (A5) that points to QD Globals
  34. //        PPC, on the other hand, doesn't have those, so you need to allocate them
  35. #ifdef    __powerc
  36.     QDGlobals        qd;
  37. #endif
  38.  
  39.  
  40. /**************************************************************************************
  41.  
  42.     main
  43.     
  44.     Entry point for our program.  We initialize the Toolbox, make sure we are
  45.     running on a sufficiently brawny machine, and put up the menu bar.  Finally,
  46.     we start polling for events and handling them by entering our main event
  47.     loop.
  48.     
  49. ***************************************************************************************/
  50. int    main()
  51. {
  52.     /*    If you have stack requirements that differ from the default,
  53.         then you could use SetApplLimit to increase StackSpace at
  54.         this point, before calling MaxApplZone. */
  55.     
  56.     MaxApplZone();            /* Expand the heap so code segments load at the top */
  57.     initToolbox();            /* Initialize the program */
  58.     MainEventLoop();        /* Call the real program which does the stuff! */
  59.     return 0;
  60. }
  61.  
  62. /**************************************************************************************
  63.  
  64.     InitToolbox
  65.     
  66.     Set up the whole world, including global variables, Toolbox managers, and menus.
  67.     
  68. ***************************************************************************************/
  69. void    initToolbox( void)
  70. {
  71.     Handle        menuBar;
  72.     EventRecord    event;
  73.     short        count;
  74.     WINDOWOBJ  *tempWindowObj;
  75.     long        threadsPresentBit;
  76.     
  77.     
  78.     gInBackground = false;
  79.     gQuit = false;
  80.     
  81.     InitGraf( (Ptr) &qd.thePort);
  82.     InitFonts();
  83.     InitWindows();
  84.     InitMenus();
  85.     TEInit();
  86.     InitDialogs(NIL);
  87.     InitCursor();
  88.     
  89.     /*    This next bit of code waits until multi-finder brings our application
  90.         to the front.  This gives us a better effect if we open a window at
  91.         startup. */
  92.     
  93.     for( count = 1; count <= 3; ++count)
  94.         EventAvail(everyEvent, &event);
  95.     
  96.     SysEnvirons(curSysEnvVers, &gMac);
  97.     
  98.     if( gMac.machineType < 0)
  99.         DeathAlert( errWimpyROMs);
  100.     if( gMac.processor < env68020)
  101.         DeathAlert( errWimpy68K);
  102.     if( gMac.systemVersion < 0x0700)
  103.         DeathAlert( errWimpySystem);
  104.     if( gMac.hasColorQD == false)
  105.         DeathAlert( errWimpyQD);
  106.  
  107.     if( Gestalt( gestaltThreadMgrAttr, &threadsPresentBit) != noErr)
  108.         DeathAlert(errNoThreads);
  109.  
  110.     if( ((1<<gestaltThreadMgrPresent) & threadsPresentBit) == 0)
  111.         DeathAlert(errNoThreads);
  112.     
  113.     menuBar = GetNewMBar( rMenuBar);        /* Read menus into menu bar */
  114.     if( menuBar == NIL)
  115.         DeathAlert( errNoMenuBar);
  116.     SetMenuBar( menuBar);                    /* Install our menus */
  117.     DisposHandle(menuBar);
  118.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* Add DA names to Apple menu */
  119.     
  120.     AppAdjustMenus();
  121.     DrawMenuBar();
  122.     
  123.     tempWindowObj = new WINDOWOBJ;        /* Object window support */
  124.     tempWindowObj->InitObj();            /* This performs initialization */
  125.     delete tempWindowObj;
  126.     
  127. }
  128.  
  129. /**************************************************************************************
  130.  
  131.     DeathAlert
  132.     
  133.     Display an alert that tells the user an error occurred, then exit the
  134.     program.  This routine is used as an ultimate bail-0out for serious errors
  135.     that bprohibit the continuation of the application.  The error number is
  136.     used to index an STR# resource so that a relevant message can be displayed.
  137.     
  138. ***************************************************************************************/
  139. void    DeathAlert(short errNumber)
  140. {
  141.     short        itemHit;
  142.     Str255        theMessage;
  143.     
  144.     SetCursor( &qd.arrow);
  145.     GetIndString(theMessage, rErrorStrings, errNumber);
  146.     ParamText(theMessage, NIL, NIL, NIL);
  147.     SetCursor( &qd.arrow);
  148.     itemHit = StopAlert(rErrorAlert, NIL);
  149.     ExitToShell();
  150. }
  151.  
  152.  
  153.